package com.dongdongshop.service.impl;

import com.dongdongshop.domain.AjaxResult;
import com.dongdongshop.domain.PageResult;
import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.service.BrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@DubboService
public class BrandServiceImpl implements BrandService {

    @Resource
    private TbBrandMapper brandMapper;

    @Override
    public PageResult<TbBrand> brandList(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbBrand> list = brandMapper.selectByExample(null);
        PageInfo<TbBrand> page = new PageInfo<>(list);
        PageResult pr = new PageResult();
        pr.setPageNum(page.getPageNum());
        pr.setPageSize(page.getPageSize());
        pr.setTotal(page.getTotal());
        pr.setPages(page.getPages());
        pr.setRows(page.getList());
        return pr;
    }

    @Override
    public void insert(TbBrand tbBrand) {
         brandMapper.insertSelective(tbBrand);
    }

    @Override
    public TbBrand toUpdateById(Long id) {
        return brandMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateInfo(TbBrand tbBrand) {
        brandMapper.updateByPrimaryKeySelective(tbBrand);
    }

    @Override
    public void deleteInfo(Integer[] ids) {
        brandMapper.deleteById(ids);
    }

    @Override
    public List<TbBrand> brandList1() {
        return brandMapper.selectByExample(null);
    }
}
